<template>
  <div class="home">
    
  </div>
</template>

<script>
export default {
  created() {
    // var myUrl = window.location.protocol + '//' + document.domain;
    const code = this.GetUrlParame('code') 
    if (!code) {
      var domine = window.location.href.split("#")[0];
      this.http.post("/location/index/wechat_login",{redirect_url:domine}).then(res => {
        window.location.href = res.data.data;
      });
    } else {
      this.http.post("/location/index/wechat_login",{code: code}).then(res => {
        var data = res.data;
        if(data.code == 200){
          this.$cookie.set('openid', data.openid);
        }
        var url = this.$cookie.get('myUrl');
        this.$router.push(url);
        // window.location.replace(myUrl + this.$config.pathname +  '/#' + this.$cookie.get('myUrl'));
      });
    }
  },
  methods:{
     // 截取code
    GetUrlParame (parameName) {
      var parames = window.location.search
      if (parames.indexOf(parameName) > -1) {
        var parameValue = ''
        parameValue = parames.substring(parames.indexOf(parameName), parames.length)
        if (parameValue.indexOf('&') > -1) {
          parameValue = parameValue.substring(0, parameValue.indexOf('&'))
          parameValue = parameValue.replace(parameName + '=', '')
          return parameValue
        }
        return ''
      }
    } 
  }
};
</script>
